<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="王雨峰, 博客" />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="Alan Wang&apos;s personal blog.">
<meta property="og:type" content="website">
<meta property="og:title" content="王雨峰的博客">
<meta property="og:url" content="http://wangyufeng.org/page/6/index.html">
<meta property="og:site_name" content="王雨峰的博客">
<meta property="og:description" content="Alan Wang&apos;s personal blog.">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="王雨峰的博客">
<meta name="twitter:description" content="Alan Wang&apos;s personal blog.">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://wangyufeng.org/page/6/"/>

  <title> 王雨峰的博客 </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">王雨峰的博客</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">随便写点东西，为互联网贡献一些比特~</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/c-e8-af-ad-e8-af-be-e8-ae-be-e5-bf-83-e5-be-97-e5-88-86-e4-ba-ab-e4-ba-8c/" itemprop="url">
                  C语课设心得分享(二)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T15:22:23+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <div id="article_content" class="article_content">咱们今儿说说IDE的事儿。<br><div></div><br><div>IDE是「集成开发环境」的意思，比如咱们常用的VC6.0，就是开发C语言所用的IDE的一种。对于IDE的认识，可能有些朋友有点儿模糊，咱们捋一捋，我也会给出一些IDE方面的建议。下面内容都是靠印象撸的，懒得一一考证了，如有错误还请指出。</div><br><div></div><br><div>VC的全称是Visual C++，是「微软」公司的一款产品，对于咱们来说，最常用的功能就是写C语言用。在VC6.0中写好程序后，咱们需要先点「编译」，再点「链接」，这是什 么意思呢？大家可能多多少少听说过，C语言用记事本也能写，确实如此。方法大致如下，首先在记事本中写好C语言编写的程序，然后你需要有一个 gcc.exe的程序，然后利用一些参数，比如gcc xxx.c -o xxx.exe，这样就会生成一个xxx.exe文件，这个就是最终生成的可执行文件，也就是编好的程序。没了？没了。编译的过程是将.c变为.obj、 链接的话是把.obj变为.exe，GCC、包括咱们用的VS，一般都把这两个过程二合一了（当然也可通过参数拆开来做）。</div><br><div>如果说gcc(GNU C Compiler)是一把锤子，Visual C++ 6.0就相当于是一个超级强大的工具箱。当然，VC中也是有编译器的，只是用的不是gcc，而是微软自己写的编译器。</div><br><div>所以说，IDE只是个工具的集合，最基本工具的工作原理是一致的，有这么个概念比较好。</div><br><div></div><br><div>可能有人要问了，咱们学的不是C语言吗？为啥用Visual C++呢？有C语言专用的IDE吗？</div><br><div>回答上面三个问题。①C++这门语言在设计时，就考虑到兼容C语言的语法和标准库(从名字也能看的出来)，所以C语言可看做 是C++的一个子集，也就是说在C++的IDE中编写C语言是完全可行的。（ps，C++的那种编译锤子叫g++）。②因为VC好使啊，微软大法好。③ 有，比如 Turbo C，「Borland」公司的产品，这款软件是一种以屎蓝色为背景色的、以屎黄色为字体颜色的、不用使用鼠标的一款上古化石。不造大家还记得不记得咱们C 语课本上为啥有个函数死活VC不认(大概是randomize())，因为这是一个TC(Turbo C简称)中的函数，到了VC年代已经被无情抛弃了，从这里也能看出为啥我不推荐大家看太多课本。其实咱们这次课设要用到的EasyX库，就是用TC时代的 graphic.h库重新打包过来的，以方便在VC上运行。</div><br><div></div><br><div>再说说Dev-c，Code Blocks等IDE，这些IDE都是很不错的(一般是使用标准的gcc编译器，自带)，启动速度快。但是对于咱们这次的课设，我还是推荐大家使用 VS(或者VC)。比如Dev-cpp已经已经停止更新了，而且我就没成功调试过一次。Code Blocks的调试功能相比VC也是差的比较远。而且有个比较大的问题，就是EasyX这个库貌似在VC/VS上与运行效果比较好。</div><br><div></div><br><div>还有就是非常重要的调试问题，以前咱们的课后习题，我在做的过程中最多就用过F10单步调试，当然还有很多大神用瞪眼调试法。做这个课设，至少用到了断点、条件断点、变量监视、单步调试的功能，这些都是DC或者CB所很难负担的。关于调试回头再专门来写。</div><br><div></div><br><div>接着说VS，VS的全 程是Visual Studio，是微软的一种工具箱大杂烩，意思是VS不仅可以编写C++，还能有VB，C#等等软件，以微软自己的产品为主。所以Java基本是不用想 了。其实，咱们在VS中编C语言，其实还是用VS中的VC，版本的话大概是VC2010、VS2012这些。我课设用的是VS2012，比较稳定。因为装 了个VA插件，所以代码看上去都是挺漂亮的。关于这些和字体、排版等问题回头也再单说吧。VC的话可能在代码高亮上就比较挫。</div><br><div></div><br><div>忘拉单子了，好像IDE这个话题内还想写几个东西但是忘了，想起来再补充吧。</div><br></div>
          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/c-e8-af-ad-e8-a8-80-e8-af-be-e8-ae-be-e5-bf-83-e5-be-97-e5-88-86-e4-ba-ab-e4-b8-80/" itemprop="url">
                  C语言课设心得分享(一)
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T15:21:41+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>今儿上完课设，老师果然讲的比较少，周四还不用去，看来还是学生自己折腾。我在做课设的过程中，攒了一些心得/体会，希望能和大家分享分享，也希望能一起探讨探讨。如果是我能回答的问题，我很乐意能够提供帮助。</p>
<p>课设这东西是要写出一个大的整体，和咱们上学期写的那些习题不太一样。那些题都是明确给出了具体的目的。而这个课设给出了一系列较为宏观的需求，要咱们自己去设计一些综合的方法，开始时可能觉得迷茫，无从下手，不知道该干什么。我的感受是在做课设之前，心里要有几个数，或者说对几样东西有谱，这样就能有效地开始着手我们的任务。</p>
<p>1、先构思，后写代码<br>以前我试图写过一个贪吃蛇游戏，没有进行构思和设计，直接开始写代码，想到哪就写到哪，结果开发到中期时，整个程序的结构已经混乱不堪，完全无法维护，不得不放弃了程序。这回我做课设（小球移动）之前，虽然也没做什么规范、详细的设计，但至少按照一些程序设计的方法，简单勾勒了一下程序的框架。<br>比如考虑到面向过程的程序设计，那么我想我有哪些数据（输入，小球等），进而设计数据的设计结构。我选择了用链表+结构体存储小球们的信息，我在后期很多功能的拓展，得益于我为小球选择了较为正确的数据结构，因为我很方便就能添加小球的属性（在咱们将来的面向对象编程中，也就意味着还能很方便地添加小球的功能）。再考虑数据的处理，输出(显示、保存等)。<br>其中对数据的处理自然是核心任务，那我就能由此展开来，考虑模块化的程序设计方法。我将对数据处理的不同任务划分为不同模块(显示球、移动球、响应点击等)，高内聚我做的并不好，因为我经常在一个模块中完成一个以上的任务，最性质恶劣的就是我在delete_ball模块中塞进了许多功能(因为我到最后懒得再新弄一个模块再设计接口了，但现在一想也就是5分钟的事儿)。但是模块之间的低耦合我想我弄的还是不错的，除非是作为枢纽的模块，否则即使删掉某个函数应该对整体也影响不大。具体可以看我文档中的模块关系图。</p>
<blockquote>
<div style="color: #000000; font-size: 14.1176px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12.3529px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="font-family: Microsoft YaHei;"><br><br><img src="http://img.blog.csdn.net/20150306163322144?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXp6d2FjYjkwMDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt=""><br><br><br></span></div>

<div style="color: #000000; font-size: 14.1176px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12.3529px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="font-family: Microsoft YaHei;"><br><br><br></span></div>

<div style="color: #000000; font-size: 14.1176px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12.3529px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="font-family: Microsoft YaHei;">2、IDE(编程工具)的选择</span></div>

<div style="color: #000000; font-size: 14.1176px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 12.3529px; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;"><span style="font-family: Microsoft YaHei;">(未完持续)</span></div></blockquote>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/e5-b0-86c-e8-af-ad-e8-af-be-e8-ae-be-e4-bc-a0-e5-88-b0-e4-ba-86github-e5-92-8ccode-e4-b8-8a/" itemprop="url">
                  将C语课设传到了Github和Code上
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T15:19:39+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>原文发表于<span class="gray">2015-01-18</span></p>
<p>&nbsp;</p>
<p>一直听说Git好使，以前捣鼓过没弄成，现在考完试了终于可以静下心来研究研究。</p>
<p>哎，我要是当时做课设的时候就用Git，也能省下不少事呢。</p>
<p>&nbsp;</p>
<p>使用的Git教程，刚看个开头：</p>
<p>廖雪峰的Git教程</p>
<p><a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000" target="_blank" rel="external">http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000</a></p>
<p>CODE帮助文档</p>
<p><a href="https://code.csdn.net/help/CSDN_Code/CODE_Support/Index" target="_blank" rel="external">https://code.csdn.net/help/CSDN_Code/CODE_Support/Index</a></p>
<p>===========================================</p>
<p>折腾半天，终于push上去了</p>
<p>CODE : <a href="https://code.csdn.net/azzwacb9001/c_homework" target="_blank" rel="external">https://code.csdn.net/azzwacb9001/c_homework</a></p>
<p>Github: <a href="https://github.com/wangyufeng0615/c_big_homework" target="_blank" rel="external">https://github.com/wangyufeng0615/c_big_homework</a></p>
<p>===========================================</p>
<p>下一步：</p>
<p>①继续学习Git</p>
<p>②研究一下不用VC如何建立一个C语言的工程</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/e5-af-b9-e6-95-b0-e7-bb-84-e6-8c-87-e9-92-88-e7-9a-84-e7-90-86-e8-a7-a3/" itemprop="url">
                  对“数组指针”的理解
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T15:18:03+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>原文发表于<span class="gray">2014-10-25</span></p>
<p>&nbsp;</p>
<p>0.本来十分不解，不能理解形如</p>
<p><pre class="cpp">int (*p)[100];</pre><br><span style="font-family: Courier New; background-color: #f0f0f0;">这样的东西。</span></p>
<p>&nbsp;</p>
<p><span style="font-family: Courier New; background-color: #f0f0f0;">1.</span></p>
<p>百度了一下，大概理解数组指针如果用来处理二维数组，指向的是每”行“的第零个元素的地址。</p>
<p>比如有：</p>
<p><pre class="cpp">int array[100];<br>int (*p)[100];<br>p = array;<br>//第二行的100是个提示，提示你一行有100个元素</pre><br>那么有</p>
<p><pre class="cpp"><em>(p)  //array[0]，即第零行第零个元素的地址
</em>(p + i)  //array[i]<br><em>(p + i) + j    //array[i][j]的地址
</em>(*(p + i) + j) //array[i][j]的值</pre><br>&nbsp;</p>
<p>2.</p>
<p>程序L11-1，功能是输入若干字符串，找出其中最长的一句</p>
<p>原来用text[0]的实现：</p>
<p><pre class="cpp">//L11-1</pre></p>
<p>#include &lt;stdio.h&gt;</p>
<p>#include &lt;string.h&gt;</p>
<p>int main()<br>{<br>    char text[100][100] = {0};<br>    printf(“输入一些文本：\n”);</p>
<pre><code>//输入文本
int i = 0;
while(1)
{
    gets(text[i]);

    if (0 == strlen(text[i]))
    {
        break;
    }
    i++;
}

//处理
int j = 0;
char* max = text[j];
for (j = 0; j &amp;lt; i; j++)
{
    if ( strlen(max) &amp;lt; strlen(text[j+1]) )
    {
        max = text[j+1];
    }
}

printf(&quot;最长的行是%s&quot;,max);

return 0;
</code></pre><p>}<br><br>改用数组指针后：</p>
<p><pre class="cpp">//L11-1</pre></p>
<p>#include &lt;stdio.h&gt;</p>
<p>#include &lt;string.h&gt;</p>
<p>#include &lt;assert.h&gt;</p>
<p>int main()<br>{<br>    char text[100][100] = {0};<br>    printf(“输入一些文本：\n”);</p>
<pre><code>char (*p)[100];
p = text;

//输入文本
int i = 0;
while(1)
{
    gets(*(p+i));

    if (!strlen(*(p+i)))
    {
        break;
    }
    i++;
}

//处理
int j = 0;

char * max = *p;
//char (*max)[100] = text;

for (j = 0; j &amp;lt; i; j++)
{
    if ( strlen(max) &amp;lt; strlen(*(p+j)) )
    {
        max = *(p+j);
    }
}

printf(&quot;最长的行是%s&quot;,max);

return 0;
</code></pre><p>}<br><br>3.</p>
<p>此程序中有等价关系：</p>
<p><pre class="cpp">int text[20][100] = {0};</pre></p>
<p>int <em> p = text[0];<br>//等价于<br>int (</em>p)[100] = text;  //赋值关系是p = text;<br>&nbsp;</p>
<hr>
<p>4.仍然有疑问：</p>
<p>这种所谓“指向数组的指针”和普通的指向一维数组的普通指针有何区别？</p>
<p><pre class="cpp">int array1[10] = {0};<br>int * p1 = array1;</pre></p>
<p>int array2[10][10] = {0};<br>int (*p2)[10] = array2;</p>
<p>//这有区别？=.=<br>&nbsp;</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/e8-b0-a2-e5-b0-94-e5-ae-be-e6-96-af-e5-9f-ba-e4-b8-89-e8-a7-92-e5-bd-a2-ef-bc-8c-e6-b7-b7-e6-b2-8c-e6-b8-b8-e6-88-8f-e5-ae-9e-e7-8e-b0/" itemprop="url">
                  谢尔宾斯基三角形，“混沌游戏”实现
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T15:16:13+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p><span class="gray">原文发表于2014-10-22</span></p>
<p>&nbsp;</p>
<p><img src="http://img.blog.csdn.net/20141022171205404?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXp6d2FjYjkwMDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""><img src="http://img.blog.csdn.net/20141022170722093?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYXp6d2FjYjkwMDE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt=""></p>
<p>请教了一下@李劲 学长用啥图形库，学长推荐了EasyX，我就试了试做这个，原物是从《混沌与分形——科学的新疆界》p24页看到的。</p>
<p>本来还想做的更动态一些，但是没搞清楚画出的线如何删掉，干脆就不划线了。用上下键可调速。</p>
<p>疑问：</p>
<p>①、如何有效地将程序暂停很短的时间？貌似Sleep函数只能最短暂停10ms左右。我用空循环模拟了暂停，但在VS的Release生成时就毫无效果，不知道是空循环的问题还是其他问题（我怀疑后者）。</p>
<p>②、TCHAR如何用itoa等函数？（有wcscpy等TCHAR类型可使用的函数）</p>
<p>&nbsp;</p>
<p>感想：</p>
<p>①复杂性科学好好玩，<strong>我想好好学数学-_-</strong></p>
<p>②我想赶紧把c prime plus看完…最近都在干啥…</p>
<p>&nbsp;</p>
<p>说到数学，我想感谢@吴军博士 的书 @贺利坚老师 的书，让我这智商拙计的人在痛苦学数学的道路上多了几分决绝- -</p>
<p><pre class="cpp">#include &lt;stdio.h&gt;</pre></p>
<p>#include &lt;time.h&gt;</p>
<p>#include &lt;graphics.h&gt;</p>
<p>#include &lt;conio.h&gt;</p>
<p>#include &lt;string.h&gt;</p>
<p>#define TIMES 200000      //画点的次数</p>
<p>#define SPEED 2000000      //初始速度(数值越大画得越慢，空循环次数)</p>
<p>POINT pts_tri[3] = { {-200,0} , {200,0} , {0,350} }; //画布顶点<br>int x, y; //坐标<br>int dir; //方向键</p>
<p>//画三角形边框<br>void draw_flame()<br>{<br>    polygon(pts_tri, 3);<br>}</p>
<p>void draw()<br>{<br>    switch ( (rand() % 3) + 1 )<br>    {<br>    case 1 :<br>        putpixel((getx() + (-200)) / 2 , gety() / 2 , GREEN);<br>        x = (getx() + (-200)) / 2;<br>        y = gety() / 2;<br>        moveto(x, y);<br>        break;<br>    case 2 :<br>        putpixel((getx() + 200) / 2 , gety() / 2 , GREEN);<br>        x = (getx() + 200) / 2;<br>        y = gety() / 2;<br>        moveto(x, y);<br>        break;<br>    case 3 :<br>        putpixel(getx() / 2, (gety() + 350) / 2 , GREEN);<br>        x = getx() / 2;<br>        y = (gety() + 350) / 2;<br>        moveto(x, y);<br>        break;<br>    }<br>}</p>
<p>int recieve_direction(int speed)<br>{<br>    dir = getch();<br>    if (-32 == dir)<br>        dir = getch();</p>
<pre><code>//up 加速
if (72 == dir)
{
    speed -= 999999;
    if ((speed - 999999) &amp;lt;= 0)
    {
        speed = 0;
        return speed;
    }
    return speed;
}

//down 减速
if (80 == dir)
    speed += 999999;
return speed;
</code></pre><p>}</p>
<p>//itoa不能处理TCHAR，outtextxy又只能用TCHAR-_-<br>void print_text(int speed, TCHAR* text_1)<br>{<br>    settextcolor(WHITE);<br>    outtextxy(-180, 320, text_1);</p>
<pre><code>/*    
TCHAR text_speed[10] = {0};
_itoa(speed, text_speed, 10);
wcscpy(text_speed, speed);
outtextxy(-180, 300, text_speed);
*/
</code></pre><p>}</p>
<p>int main()<br>{<br>    int speed = SPEED; //速度</p>
<pre><code>srand((unsigned)time(NULL));

initgraph(640, 480);    //画布
setorigin(320, 400);    //坐标原点
setaspectratio(1, -1);    //坐标轴正向

draw_flame(); //画边框

moveto(0, 0); //初始点，尚无随机效果

TCHAR text_1[] = _T(&quot;↓ +   ↑ -&quot;); //坐标轴已经上下反过来了怎么办-_-

for (int i = 0; i &amp;lt; TIMES; i++)
{
    draw();
    print_text(speed, text_1); //显示速度

    //检测上下按键，改变速度
    while (kbhit())
    {
        speed = recieve_direction(speed);
    } 

    //调速
    for (int j = 0; j &amp;lt; speed; j++)
        ;
}

getchar();
return 0;
</code></pre><p>}<br><br>&nbsp;</p>

          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/e9-b8-a1-e5-85-94-e5-90-8c-e7-ac-bc-e9-9a-8f-e6-9c-ba-e6-95-b0-e7-9e-8e-e8-92-99-e7-9a-84-e5-ae-9e-e7-8e-b0/" itemprop="url">
                  鸡兔同笼随机数瞎蒙的实现
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T15:14:14+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>原文发表于<span class="gray">2014-10-08</span></p>
<p>&nbsp;</p>
<p>今天C语小测验，这个思路还被老师批判了一番=.=</p>
<p>&nbsp;</p>
<p>产生一个疑问：这个程序我循环10W次，如果在CMD里把每次循环的结果都显示出来，就得大约用半分钟的时间。如果我不printf每次的结果，大概3秒钟就能出最后的答案。</p>
<p>&nbsp;</p>
<p>是CMD里的刷新速度有限制吗？有啥办法能既显示数据又能充分利用CPU的能力？</p>
<p>&nbsp;</p>
<pre class="cpp">#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;stdlib.h&gt;
//实验多少次
#define TIME 100000
//是否显示每次试验的数据
#define ECHO 0

void calculate_average(int*, int, int*);

int main()
{
    int rabbit, chick;
    int i; //每次试验蒙的次数
    int* count = malloc(sizeof(int)*TIME); //count指针
    int times = 0; //试验的总次数
    int* count_first = count; //记录count的最初地址

    srand((unsigned)time(NULL));

    while(1)
    {
        rabbit = rand()%36;
        chick = rand()%36;
        i++;

        if (35 == rabbit + chick &amp;&amp; 94 == rabbit * 2 + chick * 4)
        {
                if (1 == ECHO)
                {
                    printf("%-4d次瞎蒙，得出兔子有%d个，鸡有%d枚，程序走了%d次\n",i,rabbit,chick,times);
                }

                *count = i; //把当前试验的次数保存到count
                count++;
                times++;
                i = 0;
                    while (TIME == times)
                    {
                        goto break_all; //跳出大循环
                    }
        }
    }
    break_all:

    calculate_average(count, times, count_first);

    return 0;
}

void calculate_average(int * count, int times, int* count_first)
{
    int sum = 0;
    int j;

    for (j = 0; j &lt; times; j++)
    {
        sum += *count_first;
        count_first++;
    }
    printf("经过了%d试验,每次平均瞎蒙了%5d次\n",times,sum/times);
}
</pre>
          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
      

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                
                <a class="post-title-link" href="/2015/03/28/e8-af-b4-e5-88-b0-e5-85-b3-e4-ba-8e-e8-bf-b7-e5-ae-ab-e8-af-be-e8-ae-be/" itemprop="url">
                  说到关于迷宫课设
                </a>
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2015-03-28T14:53:46+08:00" content="2015-03-28">
              2015-03-28
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/代码/" itemprop="url" rel="index">
                    <span itemprop="name">代码</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>原文发表于<span class="gray">2014-08-26</span></p>
<p>&nbsp;</p>
<p>群里聊天，听说上一届C语言的课设是做个迷宫，我当然是不会啦，但从视觉效果上我写了这么个东西。喜感啊</p>
<p>疑问：</p>
<p>①SetConsoleOutputCP，是否跟那个啥Unicode的页有关系？</p>
<pre class="cpp">#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;windows.h&gt;

int i,j,k;

int main()
{
    SetConsoleOutputCP(437);

    for (k = 0; k &lt; 500; k++)
    {
        if (k % 500 == 0)
            printf("\n");
        else
            for (i = 0; i &lt; 10; i++)
            {   
                j = rand();
                if      (j &gt; 0 &amp;&amp; j &lt;= 3000)
                    {}
                else if (j &gt; 3000 &amp;&amp; j &lt;= 6000)
                    printf("%c",185);  
                else if (j &gt; 6000 &amp;&amp; j &lt;= 9000)
                    printf("%c",186);  
                else if (j &gt; 9000 &amp;&amp; j &lt;= 12000)
                    printf("%c",187);  
                else if (j &gt; 12000 &amp;&amp; j &lt;= 15000)
                    printf("%c",188);  
                else if (j &gt; 15000 &amp;&amp; j &lt;= 18000)
                    printf("%c",200);  
                else if (j &gt; 18000 &amp;&amp; j &lt;= 21000)
                    printf("%c",201);  
                else if (j &gt; 21000 &amp;&amp; j &lt;= 24000)
                    printf("%c",202);  
                else if (j &gt; 27000 &amp;&amp; j &lt;= 29000)
                    printf("%c",203);  
                else 
                    printf("%c",204);   
            } 
    } 

    getchar();
    return 0;    
}

</pre>
          
        
      
    </div>

    <div>
      
    </div>

    <div>
      
    </div>

    <footer class="post-footer">
      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </article>


    
  </section>

  
  <nav class="pagination">
    <a class="extend prev" rel="prev" href="/page/5/"><i class="fa fa-angle-left"></i></a><a class="page-number" href="/">1</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><span class="page-number current">6</span>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel  sidebar-panel-active ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.gif"
               alt="Alan" />
          <p class="site-author-name" itemprop="name">Alan</p>
          <p class="site-description motion-element" itemprop="description">Alan Wang's personal blog.</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">57</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">9</span>
                <span class="site-state-item-name">分类</span>
              
            </div>
          

          
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">4</span>
                <span class="site-state-item-name">标签</span>
              
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

      </section>

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2016</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Alan</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a> 
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  

  

  

</body>
</html>
